package com.apes.fn.crm.customerExpand;


import com.apes.framework.api.SpringManager;
import com.apes.framework.jpa.BaseModel;
import com.apes.framework.jpa.DefaultPersistListener;
import com.apes.framework.jpa.Name;
import com.apes.framework.jpa.comment.Comment;
import com.apes.framework.jpa.generator.ApesGenerator;
import com.apes.scm.masterdata.party.model.AccessProvider;
import com.apes.scm.masterdata.party.model.PartyRole;
import com.apes.scm.masterdata.party.repository.AccessProviderRepository;
import lombok.Getter;
import lombok.Setter;
import org.hibernate.annotations.DynamicInsert;
import org.hibernate.annotations.DynamicUpdate;
import org.hibernate.annotations.SelectBeforeUpdate;

import javax.persistence.*;
import java.util.ArrayList;
import java.util.List;

@Getter
@Setter
@SelectBeforeUpdate
@DynamicInsert
@DynamicUpdate
@Entity
@EntityListeners(DefaultPersistListener.class)
@Table(name = FnCustomerInfo.CONST_TABLE_NAME)
public class FnCustomerInfo extends BaseModel {

    public static final String CONST_TABLE_NAME = "fn_customer_info";

    @Id
    @Column(name = "id", length = 32)
    @ApesGenerator(code = CONST_TABLE_NAME, name = "赋能客户信息表")
    @Comment("编码")
    private String id;

    @Column(name = "user_id", length = 32)
    @Comment("App会员编码")
    private Long userId; // 实际没有太大作用

    @Column(name = "realname", length = 32)
    @Comment("客户名称")
    private String realname;

    @Column(name = "mobile", length = 32)
    @Comment("客户手机号")
    private String mobile;

    @Column(name = "sex")
    @Comment("性别编码")
    private Integer sex; //性别:1男 2女 0未知

    @Column(name = "sex_label")
    @Comment("性别名称")
    private String sexLabel;

    @Column(name = "user_role_id")
    @Comment("用户身份编码")
    private String userRoleId;

    @Column(name = "user_role_name")
    @Comment("会员身份名称")
    private String userRoleName;

    @Column(name = "customer_level_id")
    @Comment("客户等级编码")
    private String customerLevelId;

    @Column(name = "customer_level_name")
    @Comment("客户等级编码")
    private String customerLevelName;

    @Column(name = "customer_liveness_id")
    @Comment("客户活跃度编码")
    private String customerLivenessId;

    @Column(name = "customer_liveness_name")
    @Comment("客户活跃度名称")
    private String customerLivenessName;

    @Column(name = "vendor_code")
    @Comment("接入商编码")
    private String vendorCode;

    @Column(name = "vendor_name")
    @Comment("接入商名称")
    private String vendorName;


    /*** 车辆 ***/
    @Name
    @Column(name = "car_license", length = 64)
    @Comment("车牌号码")
    private String carLicense;

    @Column(name = "vin", length = 64)
    @Comment("车架号")
    private String vin;

    @Column(name = "jekun_model_code", length = 64)
    @Comment("配置车型编码")
    private String jekunModelCode;

    @Column(name = "car_model_label", length = 256)
    @Comment("配置车型名称")
    private String carModelLabel;


    @Column(name = "car_Model_Service", length = 64)
    @Comment("车型服务等级")
    private String carModelService;

    @Column(name = "unit_client_id", length = 64)
    @Comment("单位会员编码")
    private String unitClientId;

    @Column(name = "unit_client_name", length = 64)
    @Comment("单位会员名称")
    private String unitClientName;

    @ManyToOne(optional = false)
    @JoinColumn(name = "fn_customer_expand_id", referencedColumnName = "id", nullable = false)
    @Comment("车辆扩展表")
    private FnCustomerExpand fnCustomerExpand;

    @Comment("单位客户")
    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "unit_Client", referencedColumnName = "id")
    private PartyRole unitClient;


    public AccessProvider queryAccessProvider(){
        if( vendorCode == null ) return null;
        return SpringManager.getBean(AccessProviderRepository.class).findOne(vendorCode);
    }
}











